package com.luxoft.scoremanager.server.model.bean;


import com.fasterxml.jackson.annotation.JsonProperty;
import com.luxoft.scoremanager.server.model.entity.ComponentValue;
import org.apache.log4j.Logger;

import java.io.Serializable;

public class ComponentBean implements Serializable {
    private static final long serialVersionUID = -5170875020617735653L;


    private static Logger LOG = Logger.getLogger(ComponentBean.class);

    @JsonProperty("id_component")
    private Integer id;

    private Integer componentValueId;

    private String label;

    private String existsValue;

    private String finalValue;

    private String staticData;

    public ComponentBean() {

    }

    public ComponentBean(ComponentValue componentValue) {
        if (componentValue.getComponent() != null) {
            this.id = componentValue.getComponent().getId();
            this.componentValueId = componentValue.getId();
            this.label = componentValue.getComponent().getLabel();
            this.existsValue = componentValue.getExistsValue();
            this.finalValue = componentValue.getFinalValue();
            this.staticData = componentValue.getComponent().getStaticData();
        } else {
            LOG.trace("DB error component dao doesn't exist but values id - " + componentValue.getId() + " exist");
        }
    }

    public ComponentBean(ComponentValue componentValue, String label, String existsValue, String finalValue, String staticData) {

        this.componentValueId = componentValue.getId();
        this.label = label;
        this.existsValue = existsValue;
        this.finalValue = finalValue;
        this.staticData = staticData;


    }

    @Deprecated
    public ComponentBean(Integer componentValueId, String label, String existsValue, String finalValue, String staticData) {

        this.componentValueId = componentValueId;
        this.label = label;
        this.existsValue = existsValue;
        this.finalValue = finalValue;
        this.staticData = staticData;


    }

    @Deprecated
    public ComponentBean(Integer id, Integer componentValueId, String label, String existsValue, String finalValue, String staticData) {

        this.id = id;
        this.componentValueId = componentValueId;
        this.label = label;
        this.existsValue = existsValue;
        this.finalValue = finalValue;
        this.staticData = staticData;

    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        ComponentBean componentBean = (ComponentBean) o;

        if (id != null ? !id.equals(componentBean.getId()) : componentBean.getId() != null) return false;
        if (id == null) {
            if (componentValueId != null ? !componentValueId.equals(componentBean.getComponentValueId()) : componentBean.getComponentValueId() != null) {
                return false;
            }
            if (label != null ? !label.equals(componentBean.getLabel()) : componentBean.getLabel() != null) {
                return false;
            }
            if (existsValue != null ? !existsValue.equals(componentBean.getExistsValue()) : componentBean.getExistsValue() != null) {
                return false;
            }
            if (finalValue != null ? !finalValue.equals(componentBean.getFinalValue()) : componentBean.getFinalValue() != null) {
                return false;
            }
            if (staticData != null ? !staticData.equals(componentBean.getStaticData()) : componentBean.getStaticData() != null) {
                return false;
            }
        }

        return true;
    }

    @Override
    public int hashCode() {
        return id != null ? id.hashCode() : 0;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getComponentValueId() {
        return componentValueId;
    }

    public void setComponentValueId(Integer componentValueId) {
        this.componentValueId = componentValueId;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public String getExistsValue() {
        return existsValue;
    }

    public void setExistsValue(String existsValue) {
        this.existsValue = existsValue;
    }

    public String getFinalValue() {
        return finalValue;
    }

    public void setFinalValue(String finalValue) {
        this.finalValue = finalValue;
    }

    public String getStaticData() {
        return staticData;
    }

    public void setStaticData(String staticData) {
        this.staticData = staticData;
    }


    @Override
    public String toString() {
        return "Component{" +
                "id=" + id +
                ", scoreId=" + componentValueId +
                ", label='" + label + '\'' +
                ", existsValue='" + existsValue + '\'' +
                ", finalValue='" + finalValue + '\'' +
                ", staticData='" + staticData + '\'' +
                '}';
    }


}